package LEETCODE2023.BISHUA100;

import leetcode.ListNode;

public class SolutionBM14 {
    public ListNode oddEvenList(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode ans = new ListNode(-1);
        ans.next = head;
        ListNode cur = head;
        ListNode ou = head.next;
        ListNode right = new ListNode(-1);
        right.next = ou;
        if (ou == null) {
            return head;
        }
        ListNode next = ou.next;
        while (next != null) {
            cur.next = next;
            ou.next = next.next;
            ou = next.next;
            cur = cur.next;
            if (ou != null) {
                next = ou.next;
            } else {
                break;
            }
        }
        cur.next = right.next;
        return ans.next;
    }
}
